// pages/message/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // 图标来源：https://www.iconfont.cn/collections/detail?spm=a313x.7781069.1998910419.dc64b3430&cid=23763
    menus: [
      [{
          icon: "/assets/img/message/computer.png",
          txt: "官方消息"
        },
        {
          icon: "/assets/img/message/draw.png",
          txt: "@我的"
        },
        {
          icon: "/assets/img/message/mountain.png",
          txt: "评论"
        },
        {
          icon: "/assets/img/message/phone.png",
          txt: "赞"
        },
        {
          icon: "/assets/img/message/swim.png",
          txt: "陌生人",
          rightTxt: "2021/12/13"
        },
      ]
    ],
    chats: [
      {
        id: 1,
        icon: "/assets/img/message/群聊.png",
        content: {
          cityName: "城旅·成都①群",
          msg: "今天天气不错，有人一起去春熙路逛逛吗？",
          unreadCount: 3
        },
        rightTxt: "14:30",
        isOnline: true
      },
      {
        id: 2,
        icon: "/assets/img/message/群聊.png",
        content: {
          cityName: "城旅·绵阳②群",
          msg: "推荐一家超棒的火锅店，味道绝了！",
          unreadCount: 0
        },
        rightTxt: "昨天",
        isOnline: false
      },
      {
        id: 3,
        icon: "/assets/img/message/群聊.png",
        content: {
          cityName: "城旅·重庆③群",
          msg: "周末徒步活动报名开始啦，快来参加！",
          unreadCount: 12
        },
        rightTxt: "2天前",
        isOnline: true
      },
      {
        id: 4,
        icon: "/assets/img/message/官方.png",
        content: {
          cityName: "城旅社区官方",
          msg: "欢迎加入城旅社区，发现城市美好！",
          unreadCount: 0
        },
        rightTxt: "3天前",
        isOnline: false
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 处理聊天项点击
   */
  onChatTap: function(e) {
    const chat = e.currentTarget.dataset.chat
    
    wx.navigateTo({
      url: `/pages/chat-detail/index?id=${chat.id}`
    })
  },

  /**
   * 处理搜索
   */
  onSearchInput: function(e) {
    const value = e.detail.value
    if (value.trim()) {
      wx.showToast({
        title: '搜索：' + value,
        icon: 'none'
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})